﻿using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MQTTServer.Models
{
    public class ConfigHelper
    {
        /// <summary>
        /// 读取配置文件
        /// </summary>
        /// <param name="key">键名称 如:ConnectionStrings:Default</param>
        /// <returns></returns>
        public string GetSettings(string key)
        {
            var builder = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);

            IConfigurationRoot configuration = builder.Build();
            return configuration[key];
        }
    }
}
